import scrapy


class CarSpider(scrapy.Spider):
    name = 'car'
    allowed_domains = ['https://car.autohome.com.cn/price/brand-33.html']
    # 若网址以html结尾，不能带'/'
    # start_urls = ['https://car.autohome.com.cn/price/brand-33.html/']
    start_urls = ['https://car.autohome.com.cn/price/brand-33.html']


    def parse(self, response):
        print('====================')
        #获取车名
        listName=response.xpath('//div[@class="main-title"]/a/text()')

        #获取价钱
        listPrice=response.xpath('//span[@class="lever-price red"]/span/text()')

        # j=0
        # for i in listName :
        #     print(i.extract(),'的价钱是',listPrice[j].extract())
        #     j = j + 1

# 20-23行的代码可用下面替代
        for i in range(len(listName)):
            print(listName[i].extract(),'的价钱是',listPrice[i].extract())